Skip to content

TYP: Update typing for 3.10 #61453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2025
Merged

TYP: Update typing for 3.10 #61453

merged 4 commits into from
May 19, 2025

Conversation

Dr-Irv
Copy link
Contributor

@Dr-Irv Dr-Irv commented May 18, 2025

  • Ran pyupgrade so that typing is updated to python 3.10 - that modified files in pandas/_libs
  • Updated pandas/_typing.py to have the following:
    • Use TypeAlias to declare all types
    • Change Type to use builtins.type
    • Remove Optional
    • Remove use of Union except for when it is used on a pandas type

Also fixed some other typing issues as well as an issue with running stubtest locally.

@rhshadrach rhshadrach added the Typing type annotations, mypy/pyright type checking label May 19, 2025
@rhshadrach rhshadrach changed the title update typing for 3.10 TYP: Update typing for 3.10 May 19, 2025
@@ -140,7 +140,7 @@ repos:
pass_filenames: false
types: [python]
stages: [manual]
- id: mypy
- id: stubtest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs indicated you could just say stubtest, but that didn't work without this change. Now you can run mypy and stubtest separately as part of type checking

@@ -563,7 +563,6 @@ def set_nulls(
if null_kind == ColumnNullType.USE_SENTINEL:
null_pos = pd.Series(data) == sentinel_val
elif null_kind in (ColumnNullType.USE_BITMASK, ColumnNullType.USE_BYTEMASK):
assert validity, "Expected to have a validity buffer for the mask"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validity cannot be None because of the test in line 558

Comment on lines +88 to +92
with tempfile.TemporaryDirectory() as td:
allow = os.path.join(td, "test")
with open(allow, "w+t") as allow:
allow.write("\n".join(_ALLOWLIST))
allow.flush()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, creating a temporary file and leaving it open means it can't be opened by another function. The above solves that problem.

@mroeschke mroeschke added this to the 3.0 milestone May 19, 2025
@mroeschke mroeschke merged commit 801bb24 into pandas-dev:main May 19, 2025
43 of 44 checks passed
@mroeschke
Copy link
Member

Thanks @Dr-Irv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants